package com.example.goodsmanagementcabinet.base;

import android.app.Activity;
import android.os.Looper;
import android.text.TextUtils;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.android.volley.error.VolleyError;
import com.example.goodsmanagementcabinet.otto.OttoManager;
import com.orhanobut.logger.Logger;

public class BaseFragment extends Fragment{
    public String TAG;
    public Activity mActivity;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        TAG = getClass().getName();
        OttoManager.getInstance().onSubscribe(this);
        mActivity = getActivity();
    }


    @Override
    public void onDetach() {
        super.onDetach();
        OttoManager.getInstance().offSubscribe(this);
    }

    /**
     * debug 日志
     *
     * @param msg
     */
    public void d(String msg) {
        Logger.d(msg);
    }

    /**
     * 错误日志
     *
     * @param msg
     */
    public void e(String msg) {
        Logger.e(msg);
    }

    /**
     * Toast
     *
     * @param msg
     */
    public void t(String msg) {
        boolean isMainThread = Thread.currentThread() == Looper.getMainLooper().getThread();
        if (!isMainThread) {
            Looper.prepare();
            Toast.makeText(GoodBoxManagerApp_.getInstance(), msg, Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(GoodBoxManagerApp_.getInstance(), msg, Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}
